define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'litestore_tech_question/index' + location.search,
                    add_url: 'litestore_tech_question/add',
                    edit_url: 'litestore_tech_question/edit',
                    del_url: 'litestore_tech_question/del',
                    multi_url: 'litestore_tech_question/multi',
                    multi_view: 'litestore_tech_answer/index',
                    table: 'litestore_tech_question',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'qs_type', title: __('Qs_type'), searchList: {"0":__('Qs_type 0'),"1":__('Qs_type 1'),"2":__('Qs_type 2'),"3":__('Qs_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'qs_contents', title: __('Qs_contents')},
                        {field: 'as_num', title: __('As_num')},
                        {field: 'qs_status', title: __('Qs_status'), searchList: {"0":__('Qs_status 0'),"1":__('Qs_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'),  buttons:[
                            {
                                name:'show_qr',
                                text:'查看回复',
                                icon:'fa',
                                classname:'btn btn-xs btn-primary btn-dialog',
                                url:'litestore_tech_answer/index/question_id/{id}'
                            }

                        ],
                        table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});